home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 May / Disc 2 / PCU0503CD2.iso / Crystal / Samples / CPP / 32bit / Mycall / MYCALLDC.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-18  |  13.4 KB  |  446 lines

  1. // MYCALLDoc.cpp : implementation of the CMYCALLDoc class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MYCALL.h"
  6. #include "MYCALLDc.h"
  7. #include "mainview.h"
  8. #include "windowop.h"
  9. #include "selectev.h"
  10. #include "tablelog.h"
  11. #include "logonser.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CMYCALLDoc
  20.  
  21. IMPLEMENT_DYNCREATE(CMYCALLDoc, CDocument)
  22.  
  23. BEGIN_MESSAGE_MAP(CMYCALLDoc, CDocument)
  24.     //{{AFX_MSG_MAP(CMYCALLDoc)
  25.     ON_COMMAND(ID_OPENJOB, OnOpenjob)
  26.     ON_COMMAND(ID_START, OnStart)
  27.     ON_UPDATE_COMMAND_UI(ID_OPENJOB, OnUpdateOpenjob)
  28.     ON_UPDATE_COMMAND_UI(ID_START, OnUpdateStart)
  29.     ON_COMMAND(ID_CLOSEPRINTJOB, OnCloseprintjob)
  30.     ON_UPDATE_COMMAND_UI(ID_CLOSEPRINTJOB, OnUpdateCloseprintjob)
  31.     ON_COMMAND(ID_LOGONTABLE, OnLogontable)
  32.     ON_UPDATE_COMMAND_UI(ID_LOGONTABLE, OnUpdateLogontable)
  33.     ON_COMMAND(ID_LOGONSERVER, OnLogonserver)
  34.     ON_COMMAND(ID_DISCARDSAVEDDATA, OnDiscardsaveddata)
  35.         ON_UPDATE_COMMAND_UI(ID_STATUSBARUPDATE, OnStatusUpdate)
  36.     ON_UPDATE_COMMAND_UI(ID_DISCARDSAVEDDATA, OnUpdateDiscardsaveddata)
  37.     //}}AFX_MSG_MAP
  38. END_MESSAGE_MAP()
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CMYCALLDoc construction/destruction
  42.  
  43. CMYCALLDoc::CMYCALLDoc() :  m_crpeEngine(TRUE)
  44. {
  45.     // TODO: add one-time construction code here
  46.     
  47.  
  48. }
  49.  
  50. CMYCALLDoc::~CMYCALLDoc()
  51. {
  52.     if(m_crpeJob != NULL)
  53.         m_crpeJob->Close();
  54. }
  55.  
  56. BOOL CMYCALLDoc::OnNewDocument()
  57. {
  58.     if (!CDocument::OnNewDocument())
  59.         return FALSE;
  60.  
  61.     // TODO: add reinitialization code here
  62.     // (SDI documents will reuse this document)
  63.     m_crpeJob = NULL;
  64.     m_longestString = 0;
  65.     m_statusString.LoadString(ID_STATUSBARUPDATE);
  66.     m_outputToFile = m_outputToWindow = FALSE;
  67.     return TRUE;
  68. }
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CMYCALLDoc serialization
  72.  
  73. void CMYCALLDoc::Serialize(CArchive& ar)
  74. {
  75.     if (ar.IsStoring())
  76.     {
  77.         // TODO: add storing code here
  78.     }
  79.     else
  80.     {
  81.         // TODO: add loading code here
  82.     }
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CMYCALLDoc diagnostics
  87.  
  88. #ifdef _DEBUG
  89. void CMYCALLDoc::AssertValid() const
  90. {
  91.     CDocument::AssertValid();
  92. }
  93.  
  94. void CMYCALLDoc::Dump(CDumpContext& dc) const
  95. {
  96.     CDocument::Dump(dc);
  97. }
  98. #endif //_DEBUG
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CMYCALLDoc commands
  102.  
  103. void CMYCALLDoc::OnOpenjob() 
  104. {
  105.     // TODO: Add your command handler code here
  106.  
  107.     char* filterBuf;
  108.     int strLength;
  109.     CString fileType;
  110.     CString filterName;
  111.     fileType.LoadString(IDS_FILETYPE);
  112.     filterName.LoadString(IDS_FILEFILTER);
  113.     strLength = fileType.GetLength(); 
  114.     filterBuf = new char[strLength + filterName.GetLength() + 4];
  115.  
  116.     CFileDialog fileDialog(TRUE);
  117.     lstrcpy(filterBuf,fileType);
  118.     lstrcpy(&filterBuf[strLength + 1], filterName);
  119.     lstrcat(&filterBuf[strLength + 1], "\0");
  120.  
  121.     fileDialog.m_ofn.lpstrFilter = filterBuf;
  122.         
  123.     if(fileDialog.DoModal() == IDOK){
  124.         m_statusString = "Attempting to Open: " + fileDialog.GetPathName();
  125.     
  126.         if((m_crpeJob = m_crpeEngine.OpenJob(fileDialog.GetPathName())) == NULL)
  127.             m_statusString.Format("PEOpenPrintJob Error: %d\n", m_crpeEngine.GetErrorCode());
  128.         else{
  129.             m_statusString = "Print Job Opened: " + fileDialog.GetPathName();
  130.             POSITION pos = GetFirstViewPosition();
  131.             CView* pFirstView = GetNextView( pos );
  132.             MainView* myView = (MainView *) pFirstView;
  133.             m_listBox->EnableWindow(TRUE);
  134.             myView->m_Area.EnableWindow(TRUE);
  135.             myView->m_Area.SetCurSel(-1);
  136.             myView->m_Area.InitializeAreaCombo(&(myView->m_CursorType), m_crpeJob);
  137.             myView->m_CursorType.EnableWindow(TRUE);
  138.             myView->m_CursorType.SetCurSel(-1);
  139.             
  140.             
  141.         
  142.         }
  143.     }
  144.         delete filterBuf;
  145.     
  146. }
  147.  
  148. void CMYCALLDoc::OnStart() 
  149. {
  150.     // TODO: Add your command handler code here
  151.     SelectEvent myEvent;
  152.     WindowOptions myWindowOptions;
  153.     CPropertySheet mySheet;
  154.     m_longestString = 0;
  155.     if(m_outputToFile)
  156.         m_fileOutput.close();    
  157.     m_outputToFile = m_outputToWindow = FALSE;
  158.     m_elementCount = 0;
  159.     myEvent.m_myCallDoc = myWindowOptions.m_myCallDoc = this;
  160.  
  161.     
  162.     mySheet.AddPage(&myEvent);
  163.     mySheet.AddPage(&myWindowOptions);
  164.     if(mySheet.DoModal() == IDOK){
  165.     m_crpeJob->OutputToWindow("Preview Window Event Logging", 0,0,400,400,0, (CWnd *) 0);
  166.     if(!m_crpeJob->Start())
  167.         m_statusString.Format("Print Job Error: %d", m_crpeJob->GetErrorCode());
  168.     else
  169.         m_statusString = "Start Print Job Successful";
  170.     }
  171. }
  172.  
  173. /* This funtion will take the event number and create the formatted 
  174. string(s) such that they can be displayed in the selected stream.  This
  175. is the function that will check the event and perform the appropriate type 
  176. case to get events values.  */
  177.  
  178. void CMYCALLDoc::CreateOutputString(CStringList& strList, short eventID, void* eventStruct, int seq)
  179. {    
  180.     PEReadingRecordsEventInfo* readStruct = (PEReadingRecordsEventInfo *) eventStruct;
  181.     
  182.     CString fmtString;
  183.     switch( eventID )
  184.     {
  185.     case PE_READING_RECORDS_EVENT:
  186.         {
  187.         PEReadingRecordsEventInfo* readStruct = (PEReadingRecordsEventInfo *) eventStruct;
  188.         fmtString.Format("SEQ #: %d Event Number: %d Cancelled: %d  Records Read: %d Records Selected: %d Done: %d", seq, eventID, readStruct->cancelled, readStruct->recordsRead,readStruct->recordsSelected, readStruct->done);
  189.         strList.AddTail(fmtString);
  190.         break;
  191.         }
  192.     case PE_START_EVENT:
  193.         {
  194.         PEStartEventInfo* startEvent = ( PEStartEventInfo *) eventStruct;
  195.         fmtString.Format("SEQ #: %d Event Number: %d Destination: %d",seq, eventID, startEvent->destination);    
  196.         strList.AddTail(fmtString);
  197.         break;
  198.         }
  199.     case PE_STOP_EVENT:
  200.         {
  201.         PEStopEventInfo* stopEvent = (PEStopEventInfo *) eventStruct;
  202.         fmtString.Format("SEQ #: %d Event Number: %d Destination: %d Job Status: %d", seq, eventID, stopEvent->destination, stopEvent->jobStatus);
  203.         strList.AddTail(fmtString);
  204.         break;
  205.         }
  206.     case PE_CLOSE_PRINT_WINDOW_EVENT:
  207.     case PE_PRINT_BUTTON_CLICKED_EVENT:
  208.     case PE_EXPORT_BUTTON_CLICKED_EVENT:
  209.     case PE_FIRST_PAGE_BUTTON_CLICKED_EVENT:
  210.     case PE_PREVIOUS_PAGE_BUTTON_CLICKED_EVENT:
  211.     case PE_NEXT_PAGE_BUTTON_CLICKED_EVENT:
  212.     case PE_LAST_PAGE_BUTTON_CLICKED_EVENT:
  213.     case PE_CANCEL_BUTTON_CLICKED_EVENT:
  214.     case PE_ACTIVATE_PRINT_WINDOW_EVENT:
  215.     case PE_DEACTIVATE_PRINT_WINDOW_EVENT:
  216.         {
  217.             PEGeneralPrintWindowEventInfo* genWinEvent = (PEGeneralPrintWindowEventInfo *) eventStruct;
  218.             fmtString.Format("SEQ #: %d Event Number: %d Window Handle: %d", seq, eventID, genWinEvent->windowHandle);
  219.             strList.AddTail(fmtString);
  220.             break;
  221.         }
  222.     case PE_ZOOM_LEVEL_CHANGING_EVENT:
  223.         {    
  224.             PEZoomLevelChaningEventInfo* zoomLevel = (PEZoomLevelChaningEventInfo *) eventStruct;
  225.             fmtString.Format("SEQ #: %d Event Number: %d ZoomLevel: %d Window Handle: %d", seq ,eventID, zoomLevel->zoomLevel, zoomLevel->windowHandle);
  226.             strList.AddTail(fmtString);
  227.             break;
  228.         }
  229.     case PE_CLOSE_BUTTON_CLICKED_EVENT:
  230.         {
  231.             PECloseButtonClickedEventInfo* closeButton = (PECloseButtonClickedEventInfo *) eventStruct;
  232.             fmtString.Format("SEQ #: %d Event Number: %d View Index: %d Window Handle: %d", seq, eventID, closeButton->viewIndex, closeButton->windowHandle);
  233.             strList.AddTail(fmtString);
  234.             break;
  235.         }
  236.     
  237.     case PE_SEARCH_BUTTON_CLICKED_EVENT:
  238.         {
  239.             PESearchButtonClickedEventInfo* searchButton = (PESearchButtonClickedEventInfo *) eventStruct;
  240.             fmtString.Format("SEQ #: %d Event Number: %d  Window Handle: %d Search String: %s", seq, eventID, searchButton->windowHandle, searchButton->searchString);
  241.             strList.AddTail(fmtString);
  242.             break;
  243.         }
  244.  
  245.     case PE_GROUP_TREE_BUTTON_CLICKED_EVENT:
  246.         {
  247.             PEGroupTreeButtonClickedEventInfo* groupTree = ( PEGroupTreeButtonClickedEventInfo *) eventStruct;
  248.             fmtString.Format("SEQ #: %d Event Number: %d Visible: %d Window Handle: %d", seq, eventID, groupTree->visible, groupTree->windowHandle);
  249.             strList.AddTail(fmtString);
  250.             break;
  251.         }
  252.     case PE_SHOW_GROUP_EVENT:
  253.         {
  254.             PEShowGroupEventInfo* showGroup = (PEShowGroupEventInfo *) eventStruct;
  255.             CString tempStr;
  256.             fmtString.Format("SEQ #: %d Event Number: %d Group Level: %d Window Handle: %d Group List: ", seq, eventID, showGroup->groupLevel, showGroup->windowHandle);
  257.             strList.AddTail(fmtString);
  258.             for(int count = 0; count < showGroup->groupLevel; count++){
  259.                 
  260.                     tempStr.Format("Group Level #[%d]: %s",(count + 1), showGroup->groupList[count]);
  261.                         strList.AddTail(tempStr);
  262.                 
  263.                 
  264.             }
  265.             //    showGroup->groupList++;
  266.             break;
  267.             }
  268.     case PE_DRILL_ON_GROUP_EVENT:
  269.         {
  270.             PEDrillOnGroupEventInfo* groupEvent = (PEDrillOnGroupEventInfo *) eventStruct;
  271.             CString tempStr;
  272.             fmtString.Format("SEQ #: %d Event Number: %d Drill Type: %d Group Level: %d Window Handle: %d Group List: ", seq, eventID, groupEvent->drillType, groupEvent->groupLevel, groupEvent->windowHandle);
  273.             strList.AddTail(fmtString);
  274.             for(int count = 0; count < groupEvent->groupLevel; count++){
  275.                 
  276.                     tempStr.Format("Group Level #[%d]: %s", (count + 1), groupEvent->groupList[count]);
  277.                     strList.AddTail(tempStr);
  278.             
  279.             
  280.             }
  281.             //    showGroup->groupList++;
  282.             break;
  283.             }
  284.     
  285.     case PE_DRILL_ON_DETAIL_EVENT:
  286.         {
  287.             PEDrillOnDetailEventInfo* detailEvent = (PEDrillOnDetailEventInfo *) eventStruct;
  288.             fmtString.Format("SEQ #: %d Event Number: %d Window Handle: %d Select Field Index: %d nField Value: %d ", seq, eventID, detailEvent->windowHandle, detailEvent->selectedFieldIndex, detailEvent->nFieldValue);
  289.             
  290.             if(detailEvent->selectedFieldIndex != -1){
  291.                 fmtString += "Field List: ";
  292.                 strList.AddTail(fmtString);
  293.                 for(int count = 0; count < detailEvent->nFieldValue; count++){
  294.                     PEFieldValueInfo* fieldValue = detailEvent->fieldValueList[count];
  295.                     CString tempStr, mainStr;
  296.                     mainStr.Format("Field Index #[%d]: Field Name: %s  Field Data Type: %d Field Value: ",count,fieldValue->fieldName, fieldValue->fieldValue.valueType);
  297.                     ValInfotoString(tempStr, &fieldValue->fieldValue);
  298.             
  299.                     mainStr += tempStr;
  300.                     strList.AddTail(mainStr);
  301.                 }
  302.             }
  303.             else
  304.                 strList.AddTail(fmtString);
  305.             break;
  306.         }
  307.  
  308.     default:
  309.         break;
  310.     }
  311. }
  312.  
  313. // Helper function that will convert valinfo information and place in a string.
  314. void CMYCALLDoc::ValInfotoString(CString& value, PEValueInfo* valInfo)
  315. {
  316.     switch(valInfo->valueType){
  317.     case PE_VI_NUMBER:
  318.         value.Format("%f", valInfo->viNumber);
  319.         break;
  320.     case PE_VI_CURRENCY:
  321.         value.Format("$%.2f", valInfo->viCurrency);
  322.         break;
  323.     case PE_VI_BOOLEAN:
  324.         value.Format("%s", ((valInfo->viBoolean)? "TRUE" : "FALSE"));
  325.         break;
  326.     case PE_VI_INTEGER:
  327.         value.Format("%d", valInfo->viInteger);
  328.         break;
  329.     case PE_VI_DATE:  
  330.         value.Format("%d-%d-%d", valInfo->viDate[0],valInfo->viDate[1],valInfo->viDate[2]);
  331.         break;
  332.     case PE_VI_STRING:
  333.         value = valInfo->viString;
  334.         break;
  335.     case PE_VI_DATETIME:
  336.         value.Format("%d-%d-%d %d:%d:%d", valInfo->viDateTime[0],valInfo->viDateTime[1],valInfo->viDateTime[2],valInfo->viDateTime[3], valInfo->viDateTime[4], valInfo->viDateTime[5]);
  337.         break;
  338.     case PE_VI_TIME:
  339.         value.Format("%d:%d:%d", valInfo->viTime[0],valInfo->viTime[1],valInfo->viTime[2]);
  340.         break;
  341.     case PE_VI_COLOR:
  342.         value = "Color";
  343.         break;
  344.     case PE_VI_CHAR:
  345.         value.Format("%c", valInfo->viC);
  346.         break;
  347.     case PE_VI_LONG:
  348.         value.Format("%d", valInfo->viLong);
  349.         break;
  350.     case PE_VI_NOVALUE:
  351.         value = "No Value";
  352.         break;
  353.     default:
  354.         break;
  355.     }
  356. }
  357.  
  358. void CMYCALLDoc::OnUpdateOpenjob(CCmdUI* pCmdUI) 
  359. {
  360.     // TODO: Add your command update UI handler code here
  361.     (m_crpeJob == NULL)? pCmdUI->Enable(): pCmdUI->Enable(FALSE);
  362.  
  363. }
  364.  
  365. void CMYCALLDoc::OnUpdateStart(CCmdUI* pCmdUI) 
  366. {
  367.     // TODO: Add your command update UI handler code here
  368.         if(m_crpeJob != NULL){
  369.             if(!::IsWindow(m_crpeJob->GetWindowHandle()))
  370.                 pCmdUI->Enable();
  371.             else
  372.                 pCmdUI->Enable(FALSE);
  373.         }
  374.         else
  375.             pCmdUI->Enable(FALSE);
  376. }
  377.  
  378. void CMYCALLDoc::OnStatusUpdate(CCmdUI* pCmdUI)
  379. {
  380.     
  381.     
  382.     pCmdUI->SetText(m_statusString);
  383. }
  384.  
  385.  
  386. void CMYCALLDoc::OnCloseprintjob() 
  387. {
  388.     // TODO: Add your command handler code here
  389.     POSITION pos = GetFirstViewPosition();
  390.     CView* pFirstView = GetNextView( pos );
  391.     MainView* myView = (MainView *) pFirstView;
  392.     myView->m_Area.ClearVars();
  393.     myView->m_CursorType.ClearVars();
  394.     m_crpeJob->Close();
  395.     m_crpeJob = NULL;
  396.     if(m_outputToFile)
  397.         m_fileOutput.close();
  398.     m_outputToWindow = FALSE;
  399.     m_outputToFile = FALSE;
  400.     m_listBox->ResetContent();
  401.     m_listBox->SetHorizontalExtent(0);
  402.     m_listBox->EnableWindow(FALSE);
  403.     m_statusString = "Job Closed";
  404. }
  405.  
  406. void CMYCALLDoc::OnUpdateCloseprintjob(CCmdUI* pCmdUI) 
  407. {
  408.     // TODO: Add your command update UI handler code here
  409.     (m_crpeJob != NULL)? pCmdUI->Enable(): pCmdUI->Enable(FALSE);    
  410. }
  411.  
  412. void CMYCALLDoc::OnLogontable() 
  413. {
  414.     // TODO: Add your command handler code here
  415.     CTableLogon tableLogon(this);
  416.     tableLogon.DoModal();
  417.     
  418. }
  419.  
  420. void CMYCALLDoc::OnUpdateLogontable(CCmdUI* pCmdUI) 
  421. {
  422.     // TODO: Add your command update UI handler code here
  423.     (m_crpeJob != NULL)? pCmdUI->Enable(): pCmdUI->Enable(FALSE);    
  424. }
  425.  
  426. void CMYCALLDoc::OnLogonserver() 
  427. {
  428.     // TODO: Add your command handler code here
  429.     CLogonServer logonServer;
  430.     logonServer.DoModal();
  431. }
  432.  
  433. void CMYCALLDoc::OnDiscardsaveddata() 
  434. {
  435.     // TODO: Add your command handler code here
  436.     m_crpeJob->DiscardSavedData();
  437.     m_statusString = "Saved Data Removed";
  438.  
  439. }
  440.  
  441. void CMYCALLDoc::OnUpdateDiscardsaveddata(CCmdUI* pCmdUI) 
  442. {
  443.     // TODO: Add your command update UI handler code here
  444.     (m_crpeJob != NULL)? pCmdUI->Enable(): pCmdUI->Enable(FALSE);    
  445. }
  446.